#include("/template/common/layout/_page_layout.html")
#@layout()

#define css()
<style>

</style>
#end

#define js()
<script type="text/javascript">
    layui.use(['table', 'layer'], function () {
        var table = layui.table
            , layer = layui.layer
            , $ = layui.jquery
            , form = layui.form;

        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , id: 'dateTable'
            , even: true //开启隔行背景
            , size: 'sm' //小尺寸的表格
            , height: 'full-150'    //容器高度
            , cols: [[                  //标题栏
                {type: 'numbers', fixed: true, unresize: 'true'}
                , {field: 'name', title: '用户名称', minWidth: 150,sort:true}
                , {field: 'structID', title: '所属架构', minWidth: 100,sort:true}
                , {field: 'createTime', title: '创建时间', minWidth: 150,sort:true}
                , {field: 'status', title: '状态', minWidth: 100, toolbar: '#status'}
                , {field: 'option', fixed: 'right', title: '操作', minWidth: 160, align: 'center', toolbar: '#barOption'}
            ]]
            , url: '#(ctxPath)/app/OrgStructure/StructurePersonList?structureID=#(sid)'
            , method: 'get'
            , request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , page: true
            , limits: [30, 60, 90, 150, 300]
            , limit: 30 //默认采用30
            , loading: true
            , done: function (res, curr, count) {
            }
        });
        table.on('tool(dateTable)', function(obj) {
            var data = obj.data;
            if (obj.event === 'use') {
                util.sendAjax({
                    type: 'POST',
                    url: '#(ctxPath)/app/OrgStructure/personUse',
                    data: {id: data.ID},
                    loadFlag: true,
                    success: function (data) {
                        reloadTable();
                    }
                });
            }else if(obj.event === 'unuse'){
                util.sendAjax({
                    type: 'POST',
                    url: '#(ctxPath)/app/OrgStructure/personUnuse',
                    data: {id: data.ID},
                    loadFlag: true,
                    success: function (data) {
                        reloadTable();
                    }
                });
            }
        });
        reloadTable = function () {
            table.reload('dateTable', {
                url: '#(ctxPath)/app/OrgStructure/StructurePersonList?structureID=#(sid)'
                , where: {} //设定异步数据接口的额外参数
            });
        }
        // form.on('submit(search)', function(data){
        //     reloadTable(data.field.name);
        //     return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        // });
        $("#add").click(function () {
            pop_show('邀请架构人员', '#(ctxPath)/app/OrgStructure/addPerson?id=#(sid)&orgType=#(orgType)', '', '', function () {
                reloadTable();
            });
        });
    });


</script>
#end

#define content()
<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-btn-group">

            <button id="add" class="layui-btn layui-btn-small">邀请</button>

        </div>
        <table id="dateTable" lay-filter="dateTable"></table>
    </div>
</div>

<script type="text/html" id="barOption">
    #[[
    {{#  if(d.isEnable == '0'){ }}
    ]]#
        #shiroHasPermission('/app/OrgStructure/personUse')
            <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="use">启用</a>
        #end
    #[[
    {{# } }}
    ]]#

    #[[
    {{#  if(d.isEnable == '1'){ }}
    ]]#
        #shiroHasPermission('/app/OrgStructure/personUnuse')
            <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="unuse">禁用</a>
        #end
    #[[
    {{# } }}
    ]]#
</script>
<script type="text/html" id="status">

    #[[
    {{#  if(d.isEnable == '0'){ }}
    ]]#
    <a class="layui-btn layui-btn-danger layui-btn-xs">禁用</a>
    #[[
    {{#  } }}
    ]]#

    #[[
    {{#  if(d.isEnable == '1'){ }}
    ]]#
    <a class="layui-btn layui-btn-normal layui-btn-xs">启用</a>
    #[[
    {{#  } }}
    ]]#
</script>
#end